
import dayjs from "dayjs";
/**
 * @description: 获取日期
 * @param {*} date
 * @param {*} separate
 * @return {*}
 */
export function getDateStr(date = new Date(), separate = "-") {
  return dayjs(date).format("YYYY-MM-DD");
  // if (!(date instanceof Date)) return;
  // let yy = date.getFullYear();
  // let mm = padStartDay(date.getMonth() + 1);
  // let dd = padStartDay(date.getDate());
  // return `${yy}${separate}${mm}${separate}${dd}`;
}
/**
 * @description: 获取年月
 * @param {*} date
 * @param {*} separate
 * @return {*}
 */
export function getYearMonth(date = new Date(), separate = "-") {
  if (!(date instanceof Date)) return;
  let yy = date.getFullYear();
  let mm = padStartDay(date.getMonth() + 1);
  return `${yy}${separate}${mm}`;
}
/**
 * @description: 以0前填充字符串到两个长度
 * @param {*} str
 * @return {*} str
 */
export function padStartDay(str) {
  return str.toString().padStart(2, "0");
}
export function addDateStr(date, type = "day", number = 1, separate = "-") {
  const [year, month, day] = [date.substring(0,4),date.substring(5,7),date.substring(8,10)]
  const newDate = new Date(Number(year), Number(month) - 1, Number(day));
  console.log(newDate)
  return dayjs(newDate).add(number, type).format("YYYY年MM月DD日");
}
export function addDate(date = new Date(), type = "day", number = 1) {
  return dayjs(date).add(number, type).format("YYYY-MM-DD");
}
